﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathLab.Utils;
using MathLab.Messaging;

namespace MathLab.Utils
{
  class MatrixSum
  {
    /// <summary>
    /// Summing two matrixes
    /// </summary>
    /// <remarks>Matrixes must have the same dimensions and length</remarks>
    /// <param name="matrixA"></param>
    /// <param name="matrixB"></param>
    /// <returns>summed matrix</returns>
    public static double[,] Sum(double[,] matrixA, double[,] matrixB)
    {
      if (MatrixCorrectness.CheckMatrixDim(matrixA, matrixB))
      {
        double[,] matrixResult = new double[matrixA.GetLength(0), matrixA.GetLength(1)];
        for (int i = 0; i < matrixA.GetLength(0); i++)
        {
          for (int j = 0; j < matrixA.GetLength(1); j++)
          {
            matrixResult[i, j] = matrixA[i, j] + matrixB[i, j];
          }
        }
        return matrixResult;
      }
      else
      {
        throw new Exception("Could not sum matrixes: Matrixes does not have the same dimensions");
      }
    }
    /// <summary>
    /// Summing two vectors
    /// </summary>
    /// <remarks>Vectors must have the same length</remarks>
    /// <param name="vectorA"></param>
    /// <param name="vectorB"></param>
    /// <returns>summed vector</returns>
    public static double[] Sum(double[] vectorA, double[] vectorB)
    {
      if (MatrixCorrectness.CheckMatrixDim(vectorA, vectorB))
      {
        double[] vectorResult = new double[vectorA.GetLength(0)];
        for (int i = 0; i < vectorA.GetLength(0); i++)
        {
          vectorResult[i] = vectorA[i] + vectorB[i];
        }
        return vectorResult;
      }
      else
      {
        throw new Exception("Could not sum vectors: Vectors does not have the same length");
      }

    }
  }

}
